<template>
  <div>
   <city-header></city-header>
   <city-search :cities="cities"></city-search>
   <city-list :letter="letter" :cities="cities" :hotCities="hotCities"></city-list>
   <city-alpha :cities="cities" @change="handleLetterChange"></city-alpha>
  </div>
</template>

<script>
import CityHeader from './components/header'
import CitySearch from './components/search'
import CityList from './components/list'
import CityAlpha from './components/alpha'
import axios from 'axios'
export default {
  name: 'city',
  components: {
    CityHeader: CityHeader,
    CitySearch: CitySearch,
    CityList: CityList,
    CityAlpha: CityAlpha
  },
  data () {
    return {
      cities: {},
      hotCities: {},
      letter: ''
    }
  },
  methods: {
    getCityInfo () {
      axios.get('/api/city.json').then(this.getCityInfoSucc)
    },
    getCityInfoSucc (res) {
      if (res.data.ret && res.data.data) {
        this.cities = res.data.data.cities
        this.hotCities = res.data.data.hotCities
      }
    },
    handleLetterChange (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.getCityInfo()
    console.log('city')
  }
}
</script>

<style lang="stylus" scoped>

</style>
